//
//  ExploreAVListView.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/1.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "ExploreAVListView.h"
#import "AVListCell.h"
@interface ExploreAVListView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation ExploreAVListView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self createCollectionUI];
    }
    return self;
}

//-(instancetype)init{
//    if (self = [super init]) {
//        
//         [self createCollectionUI];
//    }
//    return self;
//}

/**
 创建collectioview的布局
 */
-(void)createCollectionUI{
    self.collectionView.scrollsToTop = YES;
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.flowLayout.minimumLineSpacing = scaleLeftAndRight(35);
    self.flowLayout.minimumInteritemSpacing = 0;
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.flowLayout.itemSize = CGSizeMake(scaleLeftAndRight(70), scaleTopAndBottom(90));
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, self.frame.size.height) collectionViewLayout:self.flowLayout];
    [self addSubview:self.collectionView];
    [self.collectionView registerClass:[AVListCell class] forCellWithReuseIdentifier:@"AVListCell"];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    AVListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AVListCell" forIndexPath:indexPath];
    return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 10, 0, 10);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击了哦");
}


@end
